using System;
using Android.App;
using Android.Views;
using Android.OS;
using Android.Content.PM;
using Android.Content;
using Android.Locations;

using WaterDemo;
using Reign.Core;

using Android.Graphics;
using Android.Opengl;
using Javax.Microedition.Khronos.Egl;
using Javax.Microedition.Khronos.Opengles;

namespace WaterDemo_Android
{
	//[Activity (Label = "", ConfigurationChanges=ConfigChanges.Orientation | ConfigChanges.KeyboardHidden, MainLauncher = true)]
	[Activity (MainLauncher = true)]
	public class MainActivity : Activity
	{
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);
			OS.Run(new MainApplication(this));
		}
	}
	
	public class MainApplication : Reign.Core.Application
	{
		private Game game;
		private bool loaded;
	
		public MainApplication(Activity baseActivity)
		: base(baseActivity, ApplicationTypes.OpenGL)
		{
			
		}
		
		protected override void shown ()
		{
			base.shown ();
			
			try
			{
				Console.WriteLine("FrameSize...");
				Console.WriteLine(FrameSize.X.ToString());
				Console.WriteLine(FrameSize.Y.ToString());
				
				game = new Game(this);
				loaded = true;
			}
			catch (Exception e)
			{
				Close();
				Reign.Core.Message.Show(e.Message);
				Console.WriteLine("ERROR: " + e.Message);
			}
		}
		
		protected override void closing ()
		{
			Console.WriteLine("Closing");
			loaded = false;
			if (loaded && game != null)
			{
				game.Dispose();
				game = null;
			}
			base.closing ();
		}
		
		protected override void updateScene()
		{
			if (!loaded) return;
			game.Update();
			game.Render();
		}
	}
}


